#pragma once
#include <queue>
#include <mutex>
#include <condition_variable>
#include "LockQueue.h"

template<typename T>
class LockQueue{
public:
    T pop(){
        std::unique_lock<std::mutex> lock(_mutex);
        while(_queue.empty()){
            _cond.wait(lock);
        }
        T ret=_queue.front();//返回队首元素
        _queue.pop();//弹出队首元素
        return ret;
    }
    void push(T value){
        std::unique_lock<std::mutex> lock(_mutex);
        _queue.push(value);
        _cond.notify_one();
    }
private:
    std::queue<T> _queue;
    std::mutex _mutex;
    std::condition_variable _cond;
};
